package com.softa.web.controller.custom;

import com.softa.dao.model.SysUser;
import com.softa.service.system.UserService;
import com.softa.web.controller.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by yangl on 2017/8/13.
 */
@Controller
@RequestMapping("/user/register")
public class CustomRegisterController extends BaseController {

    @Autowired
    private UserService userService;

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Integer create(SysUser user) {
        logger.info("用户注册");
        Integer status = 2;//成功
        try {
            String message=userService.createUser(user);
            if(message.equals("录入成功")){
                status = 2;
            }else if(message.equals("1")){
                status = 1;
            }
        } catch (Exception e) {
            status = 0;
            logger.error(e.getMessage());
        }
        return status;
    }

    @RequestMapping(value = "/checkusername", method = RequestMethod.POST)
    @ResponseBody
    public Integer checkusername(SysUser user) {
        Integer status = 0;//默认不存在
        try {
            status = userService.checkusername(user);
        } catch (Exception e) {
            status = 1;
            logger.error(e.getMessage());
        }
        return status;
    }
}
